package com.pingan;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * Hello world!
 */
public class App {
    public static void readDg(String path) {
        File file = new File(path);
        File[] files = file.listFiles();
        if (files != null && files.length > 0) {
            for (File file1 : files) {
                if (file1.isDirectory()) {
                    String dirPath = path + "\\" + file1.getName();
                    readDg(dirPath);
                } else {
                    System.out.println(file1.getName());
                }
            }
        }
    }

    public static void readZipFile(String path) {
        File jarFile = new File(path);
        File targetFile = new File("D:\\test\\matching-plugin_bak.jar");
        InputStream in = null;
        OutputStream os = null;
        try {
            if (!targetFile.exists()) {
                targetFile.createNewFile();
            }
            in = new FileInputStream(jarFile);
            os = new FileOutputStream(targetFile);
            byte[] data = new byte[20];
            int num = 0;
            while ((num = in.read(data)) != -1) {
                os.write(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        //readDg("D:\\test"); matching-plugin.jar
        readZipFile("D:\\test\\matching-plugin.jar");
    }
}
